//
//  AppDelegate.m
//  01-UIView、UIWindow
//
//  Created by QC.L on 16/7/14.
//  Copyright © 2016年 QC.L. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "UIView+Frame.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    // 程序的组织结构
    // 2.AppDelegate 程序的执行者,签订了 UIApplicationDelegate(协议方法可选)
    // 注意:AppDelegate 就是一个普通的类,只不多签订了协议,才有这么多方法
    // 3.ViewController 视图控制器 主要负责视图管理.
    // 4.Main.sb(视图管理) LaunchScreen.sb(负责启动页) 可视化管理 (LaunchScreen.xib)
    // 5.Assets.xcassets 主要用来管理图片素材( xcode 7以前叫 Images.xcassets)
    // 6.Info.plist(工程配置文件)
    // 模拟器
    // cmmand + 1~5 改变 模拟器大小
    // command + 左右 横屏竖屏
    
    // iOS 概述
    // iOS 为正确的写法
    
    // 1.UIWindow (程序中,只有一个主窗口)
    // 取消程序的格式化入口, Main.sb
    // 创建主window对象
    // 创建 主 window 大小与屏幕一样
    // UISceen 系统屏幕类
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    //给你的窗口填色 UIcolor 系统的颜色类
    self.window.backgroundColor = [UIColor whiteColor];
    // 让window 显示,并成为主窗口
    [self.window makeKeyAndVisible];
    // Xcode7 以后必须设置rootViewController
   ViewController *VC = [[ViewController alloc] init];
    self.window.rootViewController = VC;
//    
//    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
//    view1.backgroundColor = [UIColor redColor];
//    [self.window addSubview:view1];
    // bounds 的 x, y 影响子视图的frame, 改变坐标系
    
  //  view1.bounds = CGRectMake(30, 30, 100, 100);
    
    // frame bounds center(uiview的属性)
    // 1.frame (x, y, width, height) 视图在其父视图的位置
    // 2.bounds (x, y, width, height) 视图本身的坐标系(0, 0, width, height)
    // 3.center
    
//    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 50, 50)];
//    view2.backgroundColor = [UIColor cyanColor];
//    [view1 addSubview:view2];
    // view.frame get方法
    // frame.size 结构体
    // OC和C的内容结合, 是一个常量
    
//    CGRect rect = view1.frame;
//    rect.size.width = 100;
//    view1.frame = rect;
    // UIWindow 继承于 UIView
    // UIView(与NSOject相似, 是UI阶段的根类,大部分UI控件继承于UIView)
    
     // iOS坐标系
//    // UIView 的属性
//    UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 100, 100)];
//    testView.backgroundColor = [UIColor  blackColor];
//    [self.window addSubview:testView];
    // 透明度 默认为1
  //  testView.alpha = 0.2;
    //  tag 标记(编号)
//    testView.tag = 1000;
//    UIView *view5 = [self.window viewWithTag:1000];
     // subViews
//    UIView *arrayView = [self.window.subviews objectAtIndex:0];
//    NSLog(@"%@",arrayView);
   // testView.superview;
    // hidden 隐藏和显示
   // view2.hidden = YES;
    // 视图层级
//    UIView *firstView = [[UIView alloc] initWithFrame:CGRectMake(100, 300, 50, 50)];
//    firstView.backgroundColor = [UIColor blackColor];
//    [self.window addSubview:firstView];
    // addSubview
    // insertSubview:atIndex
    // insertSubview:aboveSubview:
    // insertSubview:belowSubview:
    // [self.window insertSubview:firstView atIndex:1];
    // CGRect CGPoint
    // UILabel(用来显示文本)
    // 如果类没有自己的初始方法, 则使用父类的
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    label.backgroundColor = [UIColor greenColor];
    [self.window addSubview:label];
    // 1.text
    label.text = @"所谓经济我叫我截屏给看看各位快给我看过给我看";
    // 2.textColor
    label.textColor = [UIColor blueColor];
    // 3.font
    label.font = [UIFont systemFontOfSize:20];
    label.font = [UIFont boldSystemFontOfSize:20];
    // 4.textAlignment 对齐方式
    label.textAlignment = NSTextAlignmentCenter;
    
    // 5.numberOflines
    // 不确定行数 写0
    label.numberOfLines = 0;
    //UIButton
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor purpleColor];
    [button setTitle:@"来点我啊!" forState:UIControlStateNormal];
    button.frame = CGRectMake(200, 250, 100, 50);
    [self.window addSubview:button];
    [button addTarget:self action:@selector(button1) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    // UITextField
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 350, 100, 50)];
    textField.backgroundColor = [UIColor cyanColor];
    [self.window addSubview:textField];
    textField.borderStyle =  UITextBorderStyleBezel;
    textField.placeholder = @"请输入...";
  textField.clearsOnBeginEditing = YES;
    // command + K 显示和收起键盘
    return YES;
}


- (void)button1{
     // 结束编辑
    [_window endEditing:YES];
    NSLog(@"qerqr");

}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
